package com.smec.remes.module.submit.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;

import com.hwangjr.rxbus.annotation.Subscribe;
import com.hwangjr.rxbus.annotation.Tag;
import com.hwangjr.rxbus.thread.EventThread;
import com.smec.moblie.R;
import com.smec.moblie.databinding.ActivityBackBinding;
import com.smec.remes.base.SmecBaseActivity;
import com.smec.remes.bean.SubmitDetails;
import com.smec.remes.module.submit.SmecSubmitPresenter;
import com.smec.remes.module.submit.adapter.SmecBackAdapter;
import com.smec.remes.util.CommonUtils;
import com.smec.remes.util.TopBarLayout;

import java.util.ArrayList;

/**
 * Created by xupeizuo on 2017/12/24.
 */

public class SmecBackActivity extends SmecBaseActivity<SmecSubmitPresenter> {

    private ActivityBackBinding activityBackBinding;
    private SmecBackAdapter smecBackAdapter;
    private String applyOrderNo="";

    @Override
    public SmecSubmitPresenter getPresenter() {
        return new SmecSubmitPresenter(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityBackBinding=DataBindingUtil.setContentView(this, R.layout.activity_back);
        initView();
        getDataFromIntent();
    }

    private void initView(){
        activityBackBinding.searchTopbar.setTopBarListener(new TopBarLayout.TopBarListener() {
            @Override
            public void setOnLeftClickListener() {
                finish();
                mRxBus.post("Refresh","true");
            }

            @Override
            public void setOnRight1ClickListener() {

            }

            @Override
            public void setOnRight2ClickListener() {

            }
        });
        smecBackAdapter=new SmecBackAdapter(this);
        activityBackBinding.backRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        activityBackBinding.backRecyclerView.setAdapter(smecBackAdapter);
    }

    private void getDataFromIntent(){
        applyOrderNo=getIntent().getStringExtra("applyOrderNo");
        activityBackBinding.getRoot().postDelayed(new Runnable() {
            @Override
            public void run() {
                mPresenter._backDetails(applyOrderNo);
            }
        },300);
    }

    @Subscribe(
            thread = EventThread.MAIN_THREAD,
            tags = {
                    @Tag("backDetails")
            }
    )

    public void _detailsSuccess(ArrayList<SubmitDetails> arrayList){
        if(CommonUtils.notEmpty(arrayList)) {
            if (CommonUtils.notEmpty(arrayList.get(0).getCanceledList())) {
                smecBackAdapter.setArrayList(arrayList.get(0).getCanceledList());
            }
        }
    }
}
